<?php 
class BaseEmployeeReportForm extends BaseReportForm
{

	public function getModelName(){
		return "Employee";
	}


	public function configure(){


		$this->widgetSchema['card_number'] = new sfWidgetFormInput();
		$this->validatorSchema['card_number'] = new sfValidatorString(array('required'=>false));


		$years2 = range(date('Y') - 50, date('Y') );
		$hiring_date_from = new sfWidgetFormDate(array('years'=>array_combine($years2,$years2)));
		$hiring_date_from = new sfWidgetFormJQueryDate(array('date_widget'=>$hiring_date_from,'config'=>'{changeMonth: true,changeYear: true,yearRange: "'.min($years2).':'.max($years2).'"}'));

		$hiring_date_to = new sfWidgetFormDate(array('years'=>array_combine($years2,$years2)));
		$hiring_date_to = new sfWidgetFormJQueryDate(array('date_widget'=>$hiring_date_to,'config'=>'{changeMonth: true,changeYear: true,yearRange: "'.min($years2).':'.max($years2).'"}'));



		$this->widgetSchema['hiring_date'] = new sfWidgetFormDateRange(array(
		'from_date'=>$hiring_date_from,
		'to_date'=>$hiring_date_to,
		));
		$this->validatorSchema['hiring_date'] = new sfValidatorDateRange(array(
		'from_date'=>new sfValidatorDate(array('date_format'=>'d-m-y','required'=>false)),
		'to_date'=>new sfValidatorDate(array('date_format'=>'d-m-y','required'=>false)),
		));



		$this->getWidgetSchema()->moveField('order_by' ,sfWidgetFormSchema::LAST);

		$this->getWidgetSchema()->setLabel('hiring_date','Hiring date <br>dd/mm/yyyy');

	}

	protected function addDepartmentColumnCriteria(Criteria $criteria, $field, $value){
		//$colname = $this->getColname($field);

		if($value){
			$criteria->addJoin(EmployeePeer::DEPARTMENT_ID  ,CodeDepartmentPeer::ID );
			$criteria->add(EmployeePeer::DEPARTMENT_ID ,$value );
		}

	}

	protected function addLeaveTypeIdColumnCriteria(Criteria $criteria, $field, $value){
		//$colname = $this->getColname($field);
		if($value){
			$criteria->addJoin(TransactionPeer::EMPLOYEE_ID   , EmployeePeer::ID );
			$criteria->add(TransactionPeer::LEAVE_TYPE_ID  , $value );
		}

	}
	protected function addCardNumberColumnCriteria(Criteria $criteria, $field, $value){
		//$colname = $this->getColname($field);
		if($value){
			$criteria->add(EmployeePeer::CARD_ID , (int)$value );
		}

	}
	protected function addEmployeeNameColumnCriteria(Criteria $criteria, $field, $value){
		//$colname = $this->getColname($field);
		if($value){
			//$criteria->addJoin(EmployeeI18nPeer::ID , EmployeePeer::ID  );
			$criteria->add(EmployeeI18nPeer::CULTURE ,sfContext::getInstance()->getUser()->getCulture() );
			$criteria->add(EmployeeI18nPeer::FIRST_NAME   , '%'.$value.'%' ,Criteria::LIKE );
			$criteria->add(EmployeeI18nPeer::SECOND_NAME    , '%'.$value.'%' ,Criteria::LIKE );
			$criteria->add(EmployeeI18nPeer::THIRD_NAME    , '%'.$value.'%' ,Criteria::LIKE );
			$criteria->add(EmployeeI18nPeer::FOURTH_NAME    , '%'.$value.'%' ,Criteria::LIKE );
		}

	}
	protected function addEmployeeIdColumnCriteria(Criteria $criteria, $field, $value){
		//$colname = $this->getColname($field);
		if($value){
			$criteria->add(EmployeePeer::ID ,$value );
		}

	}
	protected function addHiringDateColumnCriteria(Criteria $criteria, $field, $values){
		//$colname = $this->getColname($field);

		if(is_array($values) && count($values) > 0 && $values['from'] && $values['to']){
			$ctn = $criteria->getNewCriterion( EmployeePeer::HIRING_DATE , $values['from'] ,Criteria::GREATER_EQUAL  );
			$ctn2 = $criteria->getNewCriterion( EmployeePeer::HIRING_DATE , $values['to'] ,Criteria::LESS_EQUAL );
			$ctn->addAnd($ctn2);
			$criteria->add($ctn);
		}

	}


}
